<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="shortcut icon" href="./favicon.ico" />
    <title>登录</title>
    <link rel="stylesheet" href="./font/iconfont.css">
    <link rel="stylesheet" href="./css/login.css">
    <script src="./js/popup.js"></script>
    <script src="./js/request.js"></script>
    <script src="./js/cookie.js"></script>
    <script src="./js/login.js"></script>
</head>

<body>
    <h2>
        <i class="iconfont icon-wode"></i>
    </h2>
    <form action="javascript:;">
        <input type="text" name="username" placeholder="请输入用户名">
        <input type="password" name="password" placeholder="请输入密码">
        <input type="submit" value="登录">
    </form>
    <span>还没有账号，去<a href="./register.html">注册</a></span>
</body>
<!-- <script>
    var form = document.querySelector('form')
    var usernameInput = document.querySelector('[name="username"]')
    var passwordInput = document.querySelector('[name="password"]')
    form.onsubmit = function () {
        if (usernameInput.value === '' || passwordInput.value === '') {
            alert('账号和密码不能为空')
            return false
        }
        var xhr = new XMLHttpRequest;
        xhr.open('post', 'http://localhost:3000/front/api/users/login');
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        xhr.send(`username=${usernameInput.value}&password=${passwordInput.value}`)
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status >= 200 && xhr.status < 300) {
                    var res = xhr.responseText;
                    res = JSON.parse(res)
                    var { error_code, msg } = res
                    alert(msg)
                    if (error_code === 0) {
                        location.href = './index.html'
                    }
                    console.log(res);
                }
            }
        }
        // 阻止默认行为，不允许跳转
        return false
    }
</script> -->

</html>